/* GUI CONVERTED from sorp15a.p (converter v1.75) Wed Aug 23 15:23:56 2000 */
/* sorp15a.p - -BOOKINGS HISTORY BY PART Subroutine (from sosorp15)*/
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*K0LF*/
/*V8:ConvertMode=Report                                        */
/* REVISION: 5.0    LAST EDIT: 01/16/89         BY: MLB *B013* */
/* REVISION: 6.0      LAST MODIFIED: 04/10/90   BY: ftb *D002* */
/* REVISION: 6.0      LAST MODIFIED: 10/19/90   BY: afs *D112* */
/* REVISION: 6.0      LAST MODIFIED: 12/02/90   BY: afs *D237* */
/* REVISION: 8.6      LAST MODIFIED: 10/07/97   BY: mur *K0LF* */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan   */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00   BY: *N0K6* Mudit Mehta  */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

         {mfdeclre.i}

/*N0K6*/ {gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE sorp15a_p_4 "Per Column"
/* MaxLen: Comment: */

&SCOPED-DEFINE sorp15a_p_5 "Gross Margin"
/* MaxLen: Comment: */

&SCOPED-DEFINE sorp15a_p_7 "Day/Week/Month"
/* MaxLen: Comment: */

/*N0K6*
 * &SCOPED-DEFINE sorp15a_p_1 "REPORT TOTALS: "
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE sorp15a_p_2 "Total Margin"
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE sorp15a_p_3 " Total Sales"
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE sorp15a_p_6 "   Total Qty"
 * /* MaxLen: Comment: */
 *N0K6*/

/* ********** End Translatable Strings Definitions ********* */

/*K0LF*/ {wbrp02.i}
define shared variable start like wr_start.
define shared variable part like pt_part.
define shared variable part1 like pt_part.
define shared variable cust like tr_addr.
define shared variable cust1 like tr_addr.
define shared variable site like tr_site.
define shared variable site1 like tr_site.
define shared variable buyer like pt_buyer.
define shared variable prod_line like pt_prod_line.
define shared variable ptgroup like pt_group.
define shared variable part_type like pt_part_type.
define shared variable vendor like pt_vend.
define shared variable pm_code like pt_pm_code.
define variable interval as integer extent 14 format "->>>,>>9".
define variable sdate as date extent 14.
define variable salesqty as decimal extent 14 format "->>>>>>>9".
define variable salesdol as decimal extent 14 format "->>>>>>>9".
define variable salesprft as decimal extent 14 format "->>>>>>>9".
define variable due_date like tr_effdate.
define variable i as integer.
define variable j as integer.
define shared variable dwm as character format "!(1)"
label {&sorp15a_p_7}.
define shared variable idays as integer format ">>>>>9" label {&sorp15a_p_4}.
define variable monthend as integer.
define variable num_intervals as integer initial 13 format "9".
define variable tot_qty as decimal format "->>>>>>>>>>9".
define variable tot_dol as decimal format "->>>>>>>>>>9".
define variable tot_prft as decimal format "->>>>>>>>>>9".
define variable first_part like mfc_logical.
define shared variable show_profit like mfc_logical
 label {&sorp15a_p_5} initial "yes".
/*D112*/ define shared variable round_1000 like mfc_logical.

 /*  {mfdeclre.i}*/ /* MOVED mfdeclre.i TO ABOVE VARIABLES*/

   /* COMPUTE START DATES */
   sdate[1] = low_date.
   {mfcsdate.i}

   display
/*N0K6*   space(120) {&sorp15a_p_6} skip */
/*N0K6*/  space(120) getTermLabelRt("TOTAL_QUANTITY",12) format "X(12)" skip
   sdate[2] space(2) sdate[3] space(2)
   sdate[4] space(2) sdate[5] space(2)
   sdate[6] space(2) sdate[7] space(2)
   sdate[8] space(2) sdate[9] space(2)
   sdate[10] space(2) sdate[11] space(2)
   sdate[12] space(2) sdate[13] space(2)
/*N0K6*   {&sorp15a_p_3} skip */
/*N0K6*/  getTermLabelRt("TOTAL_SALES",12) format "X(12)" skip
   sdate[3] - 1 space(2) sdate[4] - 1 space(2)
   sdate[5] - 1 space(2) sdate[6] - 1 space(2)
   sdate[7] - 1 space(2) sdate[8] - 1 space(2)
   sdate[9] - 1 space(2) sdate[10] - 1 space(2)
   sdate[11] - 1 space(2) sdate[12] - 1 space(2)
   sdate[13] - 1 space(2) sdate[14] - 1 space(2)
/*N0K6*   {&sorp15a_p_2} skip */
/*N0K6*/  getTermLabel("TOTAL_MARGIN",12) format "X(12)" skip
   "--------- --------- --------- --------- --------- --------- ---------"
   "--------- --------- --------- --------- --------- ------------" skip
   with frame b no-labels width 132 page-top no-box STREAM-IO /*GUI*/ .

  /* view frame phead.*/ /* STATEMENT COMMENTED */  /*K0LF*/

   for each pt_mstr where (pt_part >= part and pt_part <= part1)
      and (pt_buyer = buyer or buyer = "" )
      and (pt_prod_line = prod_line or prod_line = "" )
      and (pt_group = ptgroup or ptgroup = "" )
      and (pt_part_type = part_type or part_type = "" )
      and (pt_vend = vendor or vendor = "" )
      and (pt_pm_code = pm_code or pm_code = "" )
      no-lock
      with frame b width 132 no-box:

      /* INITIALIZE VARIABLES */
      do i = 1 to num_intervals + 1:
     salesqty[i] = 0.
     salesdol[i] = 0.
     salesprft[i] = 0.
      end.

      /* CALCULATE SHIPMENTS FOR EACH INTERVAL */
      tot_qty = 0.
      tot_dol = 0.
      tot_prft = 0.
      first_part = yes.

      for each tr_hist where tr_part = pt_part and (tr_type = "ORD-SO" )
     and (tr_addr >= cust and tr_addr <= cust1)
     and (tr_site >= site and tr_site <= site1)
     AND ( LOOKUP(tr_site,GLOBAL_user_site) > 0) 
     and (tr_effdate >= sdate[2] and tr_effdate < sdate[14]) no-lock
     use-index tr_part_eff:
     if first_part then do:
        if page-size - line-counter < 4 then page.
        display
        pt_part pt_desc1 pt_um skip
        with frame bb no-labels width 132 STREAM-IO /*GUI*/ .
        first_part = no.
     end.
     due_date = tr_effdate.
     tot_qty = tot_qty + tr_qty_req.
     tot_dol = tot_dol + (tr_price * tr_qty_req).
     tot_prft = tot_prft + ((tr_price - (tr_mtl_std + tr_lbr_std +
       tr_ovh_std + tr_sub_std + tr_bdn_std))
       * tr_qty_req).
     do i = num_intervals + 1 to 1 by -1:
        if due_date >= sdate[i] then do:
           salesqty[i] = salesqty[i] + tr_qty_req.
           salesdol[i] = salesdol[i] + (tr_price * tr_qty_req).
           salesprft[i] = salesprft[i] +
        ( (tr_price - (tr_mtl_std + tr_lbr_std +
           tr_ovh_std + tr_sub_std + tr_bdn_std))
        * tr_qty_req).
           leave.
        end.
     end.
      end.

      if not first_part then do:
     if round_1000 then do:
        do i = 1 to num_intervals + 1:
           salesdol[i] = round(salesdol[i] / 1000, 0).
           if show_profit then
          salesprft[i] = round(salesprft[i] / 1000, 0).
        end.
        tot_dol = round(tot_dol / 1000, 0).
        if show_profit then tot_prft = round(tot_prft / 1000, 0).
     end.

     accumulate salesqty(total).
     accumulate salesdol(total).
     accumulate tot_qty(total).
     accumulate tot_dol(total).
     if show_profit then do:
        accumulate salesprft(total).
        accumulate tot_prft(total).
     end.

     display
      salesqty[2 for 12] tot_qty skip
      salesdol[2 for 12] tot_dol
     with frame cc no-labels no-box width 132 STREAM-IO /*GUI*/ .

     if show_profit then
        display skip salesprft[2 for 12] tot_prft
         with frame cc no-labels no-box width 132 STREAM-IO /*GUI*/ .

      end.

      
/*GUI*/ {mfguirex.i } /*Replace mfrpexit*/

   end.

/*N0K6*   display skip(1) {&sorp15a_p_1} skip */
/*N0K6*/  display skip(1) caps(getTermLabel("REPORT_TOTALS",28)) + ": "  format "x(30)" skip
   accum total salesqty[2] format "->>>>>>>9"
   accum total salesqty[3] format "->>>>>>>9"
   accum total salesqty[4] format "->>>>>>>9"
   accum total salesqty[5] format "->>>>>>>9"
   accum total salesqty[6] format "->>>>>>>9"
   accum total salesqty[7] format "->>>>>>>9"
   accum total salesqty[8] format "->>>>>>>9"
   accum total salesqty[9] format "->>>>>>>9"
   accum total salesqty[10] format "->>>>>>>9"
   accum total salesqty[11] format "->>>>>>>9"
   accum total salesqty[12] format "->>>>>>>9"
   accum total salesqty[13] format "->>>>>>>9"
   accum total tot_qty format "->>>>>>>>>>9" skip

   accum total salesdol[2] format "->>>>>>>9"
   accum total salesdol[3] format "->>>>>>>9"
   accum total salesdol[4] format "->>>>>>>9"
   accum total salesdol[5] format "->>>>>>>9"
   accum total salesdol[6] format "->>>>>>>9"
   accum total salesdol[7] format "->>>>>>>9"
   accum total salesdol[8] format "->>>>>>>9"
   accum total salesdol[9] format "->>>>>>>9"
   accum total salesdol[10] format "->>>>>>>9"
   accum total salesdol[11] format "->>>>>>>9"
   accum total salesdol[12] format "->>>>>>>9"
   accum total salesdol[13] format "->>>>>>>9"
   accum total tot_dol format "->>>>>>>>>>9" with frame d no-labels
   no-box width 132 STREAM-IO /*GUI*/ .

   if show_profit then display
   accum total salesprft[2] format "->>>>>>>9"
   accum total salesprft[3] format "->>>>>>>9"
   accum total salesprft[4] format "->>>>>>>9"
   accum total salesprft[5] format "->>>>>>>9"
   accum total salesprft[6] format "->>>>>>>9"
   accum total salesprft[7] format "->>>>>>>9"
   accum total salesprft[8] format "->>>>>>>9"
   accum total salesprft[9] format "->>>>>>>9"
   accum total salesprft[10] format "->>>>>>>9"
   accum total salesprft[11] format "->>>>>>>9"
   accum total salesprft[12] format "->>>>>>>9"
   accum total salesprft[13] format "->>>>>>>9"
   accum total tot_prft format "->>>>>>>>>>9" with frame d no-labels
   no-box width 132 STREAM-IO /*GUI*/ .
/*K0LF*/ {wbrp04.i}
